public class MissingTwoLcci {
    // 消失的两个数字https://leetcode.cn/problems/missing-two-lcci/submissions/677433993/
    public int[] missingTwo(int[] nums) {
        //计算出 a^b
        int tmp=0;
        for(int x:nums) tmp^=x;
        for(int i=1;i<=nums.length+2;i++) tmp^=i;

        // 找出tmp上比特位为1的那一位
        int diff=0;
        while(true) {
            if(((tmp>>diff)&1)==1)break;
            diff++;
        }
        // 将全部数字分成两组
        int ret0=0;//表示该位为0
        int ret1=0;//表示该位为1
        for(int x:nums) {
            if(((x>>diff)&1)==0) ret0^=x;
            else ret1^=x;
        }
        for(int i=1;i<=nums.length+2;i++) {
            if(((i>>diff)&1)==0) ret0^=i;
            else ret1^=i;
        }
        int[] ret=new int[2];
        ret[0]=ret0;
        ret[1]=ret1;
        return ret;
    }
}
